<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 13:08
 */

namespace app\index\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Validate;
use app\index\validate\Valid;

class Dgzgjc extends Common
{
    /**
     * 所有网点导购在岗检查
     */
    public function allnetguidecheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $hbwdbh = $this->request->param('hbwdbh');
        $hbwd = $this->request->param('hbwd');
        $hbrxm = $this->request->param('hbrxm');
        $dgyxm = $this->request->param('dgyxm');
        $this->assign([
            'hbwdbh'=>$hbwdbh,
            'hbwd'=>$hbwd,
            'hbrxm'=>$hbrxm,
            'dgyxm'=>$dgyxm,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        if($hbwdbh){
            $where['wbwdbm'] = ['like',"%{$hbwdbh}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($hbrxm){
            $where['hbr_xm'] = ['like',"%{$hbrxm}%"];
        }
        if($dgyxm){
            $where['dgyxm'] = ['like',"%{$dgyxm}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_wddgzgjc')->where($where)->count();
        $data = db('yd_wddgzgjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 所属网点导购在岗检查
     */
    public function tonetguidecheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $hbwdbh = $this->request->param('hbwdbh');
        $hbwd = $this->request->param('hbwd');
        $hbrxm = $this->request->param('hbrxm');
        $dgyxm = $this->request->param('dgyxm');
        $this->assign([
            'hbwdbh'=>$hbwdbh,
            'hbwd'=>$hbwd,
            'hbrxm'=>$hbrxm,
            'dgyxm'=>$dgyxm,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['net_id'] = ['exp',"in(select id from cg_net where stuff like '%\"".session('employee_id')."\%')"];
        if($hbwdbh){
            $where['wbwdbm'] = ['like',"%{$hbwdbh}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($hbrxm){
            $where['hbr_xm'] = ['like',"%{$hbrxm}%"];
        }
        if($dgyxm){
            $where['dgyxm'] = ['like',"%{$dgyxm}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_wddgzgjc')->where($where)->count();
        $data = db('yd_wddgzgjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 所有经销商导购检查
     */
    public function allagencyguidecheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $hbwdbh = $this->request->param('hbwdbh');
        $hbwd = $this->request->param('hbwd');
        $hbrxm = $this->request->param('hbrxm');
        $jxsmc = $this->request->param('jxsmc');
        $this->assign([
            'hbwdbh'=>$hbwdbh,
            'hbwd'=>$hbwd,
            'hbrxm'=>$hbrxm,
            'jxsmc'=>$jxsmc,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        if($hbwdbh){
            $where['wbwdbm'] = ['like',"%{$hbwdbh}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($hbrxm){
            $where['hbr_xm'] = ['like',"%{$hbrxm}%"];
        }
        if($jxsmc){
            $where['jxsmc'] = ['like',"%{$jxsmc}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_jxsdgjc')->where($where)->count();
        $data = db('yd_jxsdgjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 所属经销商导购检查
     */
    public function toagencyguidecheck(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $hbwdbh = $this->request->param('hbwdbh');
        $hbwd = $this->request->param('hbwd');
        $hbrxm = $this->request->param('hbrxm');
        $jxsmc = $this->request->param('jxsmc');
        $this->assign([
            'hbwdbh'=>$hbwdbh,
            'hbwd'=>$hbwd,
            'hbrxm'=>$hbrxm,
            'jxsmc'=>$jxsmc,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['net_id'] = ['exp',"in(select id from cg_net where stuff like '%\"".session('employee_id')."\%')"];
        if($hbwdbh){
            $where['wbwdbm'] = ['like',"%{$hbwdbh}%"];
        }
        if($hbwd){
            $where['hbwd'] = ['like',"%{$hbwd}%"];
        }
        if($hbrxm){
            $where['hbr_xm'] = ['like',"%{$hbrxm}%"];
        }
        if($jxsmc){
            $where['jxsmc'] = ['like',"%{$jxsmc}%"];
        }
        if($start&&$end){
            $where['hbrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['hbrq'] = ['>',$start];
        }elseif($end){
            $where['hbrq'] = ['<',$end];
        }

        $count = db('yd_jxsdgjc')->where($where)->count();
        $data = db('yd_jxsdgjc')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){

            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);

        return $this->fetch();
    }
}